const express = require('express');
const { 
  sendMessage, 
  getMessagesByUser, 
  getRecentChats,
  searchMessages,
  markMessagesAsRead
} = require('../controllers/messageController');
const {
  sendGroupMessage,
  getGroupMessages,
  getGroupUnreadCount,
  getAllGroupsUnreadStatus,
  searchGroupMessages
} = require('../controllers/groupMessageController');
const { protect } = require('../middlewares/auth');

const router = express.Router();

// 所有路由都需要认证
router.use(protect);

// 私人消息路由
router.post('/', sendMessage);
router.get('/chats/recent', getRecentChats);
router.get('/:userId/search', searchMessages);
router.put('/:userId/read', markMessagesAsRead);
router.get('/:userId', getMessagesByUser);

// 群组消息路由 - 先定义具体路径，再定义参数化路径
router.get('/groups/unread-status', getAllGroupsUnreadStatus);
router.post('/groups/:groupId', sendGroupMessage);
router.get('/groups/:groupId', getGroupMessages);
router.get('/groups/:groupId/search', searchGroupMessages);
router.put('/groups/:groupId/read', getGroupUnreadCount);

module.exports = router; 